package com.tool.weixin.message;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import com.tool.weixin.message.type.RespType;
import com.tool.weixin.util.MessageUtil;

/**
 * 文本消息
 * @author huff
 *
 */
public class TextMessage extends BaseMessage {
	// 消息内容
	private String Content;
	
	public TextMessage(String content,Boolean isCustomerService) {
		this.Content = content;
		this.isCustomerService = isCustomerService;
	}

	public TextMessage(String touser,String content) {
		this.FromUserName = touser;
		this.Content = content;
	}
	
	public String getContent() {
		return Content;
	}

	public void setContent(String content) {
		Content = content;
	}
	
	public Boolean getIsCustomerService() {
		return isCustomerService;
	}

	public void setIsCustomerService(Boolean isCustomerService) {
		this.isCustomerService = isCustomerService;
	}
	
	@Override
	public String toxml() {
		if(this.getIsCustomerService()) {
			this.setMsgType(RespType.TRANSFER_CUSTOMER_SERVICE);
		} else {
			this.setMsgType(RespType.TEXT);
		}
		super.toxml();
		return MessageUtil.textMessageToXml(this);
	}
	
	@Override
	public String tojson() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("touser", this.getFromUserName());
		map.put("msgtype", RespType.TEXT);
		Map<String, Object> image = new HashMap<String, Object>();
		image.put("content", this.getContent());
		map.put("text", image);
		return JSONObject.fromObject(map).toString();
	}

}
